//
//  IDAViewController.m
//  Animation
//
//  Created by iD Student on 7/10/13.
//  Copyright (c) 2013 iD Student. All rights reserved.
//

#import "IDAViewController.h"

@interface IDAViewController ()

@end

@implementation IDAViewController

- (void)viewDidLoad
{
   
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    animatedImage.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"IMG0.png"],
                                     [UIImage imageNamed:@"IMG1.png"],
                                     [UIImage imageNamed:@"IMG2.png"],
                                     [UIImage imageNamed:@"IMG3.png"],
                                     [UIImage imageNamed:@"IMG4.png"],
                                     [UIImage imageNamed:@"IMG5.png"],
                                     [UIImage imageNamed:@"IMG6.png"],
                                     [UIImage imageNamed:@"IMG7.png"],
                                     nil];
    animatedImage.animationDuration = 0.6;
    
    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(startOrStopAnimation)];
    
    [animatedImage addGestureRecognizer:tapRecognizer];
     
}


- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self startOrStopAnimation];
}

-(void) startOrStopAnimation
{
    if(animatedImage.isAnimating)
    {
        
        UIImage *currentImage = animatedImage.image;
        [animatedImage stopAnimating];
        animatedImage.image = currentImage;
   
    }
    else
    {
        [animatedImage startAnimating];
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [animatedImage release];
    [super dealloc];
}
@end
